package com.SH.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Date;

@Service
public class MailService {

    @Autowired
    private JavaMailSenderImpl mailSender;

    @Value("${spring.mail.username}")
    private String emailFrom;

    public void sendMail(String email,String username) throws MessagingException {

        MimeMessage message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setSubject("[校园二手平台]注册成功通知");
        helper.setText("尊敬的"+username+":你好!\n"+"欢迎您加入我们！",true);
        helper.setSentDate(new Date());
        helper.setTo(email);
        helper.setFrom(emailFrom);
        mailSender.send(message);

    }
}
